package org.credo.thread;

public class FirstRunnable implements Runnable{

	private int i;
	
	public void run(){
		for(;i<10;i++){
			//当线程类实现Runnable接口时,
			//如果想获取当前线程,只能用Thread.currentThread()方法.
			System.out.println(Thread.currentThread().getName()+" "+i);
		}
	}
	
	public static void main(String[] args) {
		for(int i=0;i<10;i++){
			System.out.println(Thread.currentThread().getName()+" "+i);
			if(i==2){
				FirstRunnable fr=new FirstRunnable();
				//通过new Thread(target,name)方法创建新线程
				new Thread(fr,"newThread11").start();
				new Thread(fr, "newThread22").start();
			}
		}
	}
}
